package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.service.ServiceImpl;
import com.itheima.service.StuService;
import com.itheima.utils.XmlParserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class StudentController {

    @Autowired
    ServiceImpl  stuService;

    @RequestMapping("/listStu")
    public Result listStudent(){
        //1. 加载并解析 stu.xml 文件, 获取学生信息列表
//        String file = this.getClass().getClassLoader().getResource("stu.xml").getFile();
//        List<Student> studentList = XmlParserUtils.parse(file, Student.class);

        //2. 进行逻辑处理, 处理性别、分数等级等字段
//        studentList.stream().forEach(student -> {
//            if("1".equals(student.getGender())){
//                student.setGender("男");
//            }else if("2".equals(student.getGender())){
//                student.setGender("女");
//            }
//
//            Integer score = student.getScore();
//            if(score >= 85){
//                student.setLevel("优秀");
//            }else if(score >= 60){
//                student.setLevel("及格");
//            }else{
//                student.setLevel("不及格");
//            }
//        });

        List<Student> studentList = stuService.getStuServiceList();
        //3. 响应数据
        return Result.success(studentList);
    }

}
